package com.ruoyi.system.controller;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.xml.transform.Result;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Down;
import com.ruoyi.system.service.IDownService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 资料下载Controller
 *
 * @author ruoyi
 * @date 2024-02-03
 */
@RestController
@RequestMapping("/system/danwland")
public class DownController extends BaseController
{
    @Autowired
    private IDownService downService;

    /**
     * 查询资料下载列表
     */
    @PreAuthorize("@ss.hasPermi('system:danwland:list')")
    @GetMapping("/list")
    public TableDataInfo list(Down down)
    {
        down.setState("通过");
        startPage();
        List<Down> list = downService.selectDownList(down);
        return getDataTable(list);
    }

    /**
     * 导出资料下载列表
     */
    @PreAuthorize("@ss.hasPermi('system:danwland:export')")
    @Log(title = "资料下载", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Down down)
    {
        List<Down> list = downService.selectDownList(down);
        ExcelUtil<Down> util = new ExcelUtil<Down>(Down.class);
        util.exportExcel(response, list, "资料下载数据");
    }

    /**
     * 获取资料下载详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:danwland:query')")
    @GetMapping(value = "/{fileId}")
    public AjaxResult getInfo(@PathVariable("fileId") Long fileId)
    {
        return success(downService.selectDownByFileId(fileId));
    }

    /**
     * 新增资料下载
     */
    @PreAuthorize("@ss.hasPermi('system:danwland:add')")
    @Log(title = "资料下载", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Down down)
    {
        return toAjax(downService.insertDown(down));
    }

    /**
     * 修改资料下载
     */
    @PreAuthorize("@ss.hasPermi('system:danwland:edit')")
    @Log(title = "资料下载", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Down down)
    {
        return toAjax(downService.updateDown(down));
    }

    /**
     * 删除资料下载
     */
    @PreAuthorize("@ss.hasPermi('system:danwland:remove')")
    @Log(title = "资料下载", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fileIds}")
    public AjaxResult remove(@PathVariable Long[] fileIds)
    {
        return toAjax(downService.deleteDownByFileIds(fileIds));
    }
}
